//获取指定地点附近的门店
const mapKey = '#输入腾讯地图API_KEY'
const tableId = '#输入POI tableID'
function getNearbyStores(locStr){
    var urlStr ='https://apis.map.qq.com/place_cloud/search/nearby?location='+locStr+'&radius=5000&auto_extend=1&orderby=distance('+locStr+')&table_id='+this.tableId+'&key='+this.mapKey;
    wx.showLoading({
        title: '正在查找门店',
      })
    return new Promise((resolve,reject) => {
        wx.request({
            url: urlStr,
            data: {},
            header: {'content-type':'application/json'},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: (result) => {
                //console.log(urlStr);
                var res = result.data.result;
                wx.hideLoading();
                resolve(res);
            },
            fail: (res) => {reject(res)},
            complete: () => {}
        });
    })  
}

function getAllStores(region,locStr){
    var urlStr ='https://apis.map.qq.com/place_cloud/search/region?region='+region+'&orderby=distance('+locStr+')&table_id='+this.tableId+'&key='+this.mapKey;
    //https://apis.map.qq.com/place_cloud/search/region?region=北京海淀&keyword=北四环&filter=x.price>15 and x.star=3&orderby=x.price desc&table_id=5d3581dc6ce89813ed0b2cbd&key=开发者key
    wx.showLoading({
        title: '正在查找'+region+'门店',
      })
    return new Promise((resolve,reject) => {
        wx.request({
            url: urlStr,
            data: {},
            header: {'content-type':'application/json'},
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: (result) => {
                //console.log(urlStr);
                var res = result.data.result;
                wx.hideLoading();
                resolve(res);
            },
            fail: (res) => {reject(res)},
            complete: () => {}
        });
    })  
}

module.exports={
    mapKey:mapKey,
    getNearbyStores:getNearbyStores,
    getAllStores:getAllStores
}